package com.wst.system.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wst.system.config.exception.GlobalExcetion;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wst.system.server.entity.SysOpenUser;
import com.wst.system.server.mapper.SysOpenUserMapper;
import com.wst.system.server.service.SysOpenUserService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.BeanUtils;
import com.wst.system.server.entity.vo.SysOpenUserVo;
import java.io.Serializable;
import com.wst.system.server.entity.vo.PageSearchVo;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author X.I.O
 * @since 2025-03-24
 */
@Service
@Transactional
public class SysOpenUserServiceImpl extends ServiceImpl<SysOpenUserMapper, SysOpenUser> implements SysOpenUserService {


    @Override
    public SysOpenUser getById(Serializable id){
        return super.getById(id);
    }


    @Override
    public boolean removeById(Serializable id) {
        return super.removeById(id);
    }


    @Override
    public boolean updateById(SysOpenUser sysopenuser) {
        return super.updateById(sysopenuser);
    }


    public SysOpenUser saveSysOpenUser(SysOpenUser sysopenuser) throws GlobalExcetion {
        super.save(sysopenuser);
        return sysopenuser;
    }


    public SysOpenUser updateSysOpenUserById(SysOpenUser sysopenuser) throws GlobalExcetion{
        super.updateById(sysopenuser);
        return sysopenuser;
    }


    public SysOpenUser saveOrUpdateSysOpenUser(SysOpenUserVo sysopenuserVo) throws GlobalExcetion{
        SysOpenUser sysopenuser=new SysOpenUser();
        BeanUtils.copyProperties(sysopenuserVo,sysopenuser);
        if(sysopenuserVo.getId()!=null){
            SysOpenUser sysopenuserEntity=super.baseMapper.selectById(sysopenuserVo.getId());
            if(sysopenuserEntity==null){
                throw new GlobalExcetion(1,"数据不存在");
            }
            super.baseMapper.updateById(sysopenuser);
        }else{
            super.baseMapper.insert(sysopenuser);
        }
        return sysopenuser;
    }

    public IPage<SysOpenUser> page(PageSearchVo vo) throws GlobalExcetion{
        LambdaQueryWrapper<SysOpenUser> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        IPage<SysOpenUser> iPage=super.baseMapper.selectPage(new Page(vo.getPageNum(), vo.getPageSize()),lambdaQueryWrapper);
        return iPage;
    }
}